using KIMS;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents()
                .AddInteractiveServerComponents()
                .AddInteractiveWebAssemblyComponents();
builder.Services.AddApplicationWeb(option =>
{
    option.App.WebRoot = builder.Environment.WebRootPath;
    option.App.ContentRoot = builder.Environment.ContentRootPath;
    option.App.Assembly = typeof(Program).Assembly;
    option.App.Database = db =>
    {
        var connString = builder.Configuration.GetSection("ConnString").Get<string>();
#if (DatabaseType == "Access")
        db.AddAccess<System.Data.OleDb.OleDbFactory>(connString);
#elif (DatabaseType == "SQLite")
        db.AddSQLite<Microsoft.Data.Sqlite.SqliteFactory>(connString);
#elif (DatabaseType == "SqlServer")
        db.AddSqlServer<Microsoft.Data.SqlClient.SqlClientFactory>(connString);
#elif (DatabaseType == "Oracle")
        db.AddSqlServer<Oracle.ManagedDataAccess.Client.OracleClientFactory>(connString);
#elif (DatabaseType == "MySql")
        db.AddMySql<MySqlConnector.MySqlConnectorFactory>(connString);
#elif (DatabaseType == "PgSql")
        db.AddPgSql<Npgsql.NpgsqlFactory>(connString);
#elif (DatabaseType == "DM")
        db.AddDM<Dm.DmClientFactory>(connString);
#endif
        //db.SqlMonitor = c => Console.WriteLine($"{DateTime.Now:HH:mm:ss} {c}");
    };
});

var app = builder.Build();

if (app.Environment.IsDevelopment())
    app.UseWebAssemblyDebugging();
else
    app.UseHsts();

app.UseHttpsRedirection();
app.UseApplication();
app.MapRazorComponents<App>()
   .AddInteractiveServerRenderMode()
   .AddInteractiveWebAssemblyRenderMode()
   .AddAdditionalAssemblies([.. Config.Assemblies]);
app.Run();